<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
	xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc"
	xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
	xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">

	<mulexml:namespace-manager>
		<mulexml:namespace prefix="a"
			uri="http://wgrus.com/Accounting" />
	</mulexml:namespace-manager>

	<flow name="AccountingCustomerUpdateEventFlow1" doc:name="AccountingCustomerUpdateEventFlow1">


		<jms:inbound-endpoint queue="ACCOUNTING.CUSTOMER"
			connector-ref="Active_MQ" doc:name="JMS" />
        
               <set-variable variableName="test" value="#[xpath('//CustomerId').text]" doc:name="Variable"/>
        
        
		<all doc:name="All">
			<async doc:name="AsyncAsyncCallCenterUpdateCustomer">
				<jdbc-ee:outbound-endpoint
					exchange-pattern="one-way" queryKey="UpdateCustomer" queryTimeout="-1"
					connector-ref="Database" doc:name="Database">
					<jdbc-ee:query key="InsertCustomer"
						value="INSERT INTO dbo.Customer ([TelefonNr]
                    ,[Navn]
           ,[Gade]
           ,[PostNr]
           ,[By]
           ,[Oprettet]
           ,[Email]
           ,[Source])          
     VALUES
           (#[xpath('//a:CustomerId').text]
           ,#[xpath('//a:Navn').text]
           ,#[xpath('//a:Gade').text]
           ,#[xpath('//a:PostNr').text]
           ,#[xpath('//a:By').text]
           ,#[xpath('//a:Oprettet').text]
           ,#[xpath('//a:Email').text]
           ,'MULE')
                                   
                    " />

					<jdbc-ee:query key="UpdateCustomer"
						value="UPDATE dbo.Customer SET 
								 [Navn] = #[xpath('//Navn').text]
								,[Gade] = #[xpath('//Gade').text]
           						,[PostNr] =	#[xpath('//PostNr').text]	
           						,[By] =		#[xpath('//By').text]
           		           		,[Email] =	#[xpath('//Email').text]
						WHERE TelefonNr = #[xpath('//CustomerId').text]                     
                    " />

				</jdbc-ee:outbound-endpoint>
			</async>
			<async doc:name="AsyncWebShopUpdateCustomer">
				<vm:outbound-endpoint exchange-pattern="one-way"
					path="dummy" doc:name="VM" />
			</async>

		</all>
	</flow>
</mule>
